package org.openit.portail.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.openit.portail.dao.ModeleDao;
import org.openit.portail.model.ModelePaiement;
import org.openit.portail.service.ModeleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ModelServiceImpl implements ModeleService {

	@Autowired(required = true)
	private ModeleDao modeleDao;
	
	public void saveOrUpdateModele(ModelePaiement modele) {
		// TODO Auto-generated method stub
		modeleDao.save(modele);
	}

	public List<ModelePaiement> getModeles(boolean all) {
		if(!all){
		List<ModelePaiement> modelePaiements=modeleDao.findAll();
		List<ModelePaiement> modelePaiements2=new ArrayList<ModelePaiement>();
		for(ModelePaiement modelePaiement:modelePaiements){
			if(modelePaiement.getDateDebut().before(new Date()) && modelePaiement.getDateFin().after(new Date()))
				modelePaiements2.add(modelePaiement);
		}
		return modelePaiements2;
		}
		return modeleDao.findAll();
	}

	public ModelePaiement getModele(int id) {
		// TODO Auto-generated method stub
		return modeleDao.get((long) id);
	}

	public void deleteModele(ModelePaiement modelePaiement) {
//		for(ModeleParametre parametre:modelePaiement.getModeleParametre()){
//			modeleParametreDao.delete(parametre);
//		}
//		modelePaiement.setModeleParametre(null);
		modeleDao.delete(modelePaiement);

	}

	public List<ModelePaiement> getModelesForService(Long idservice) {
		return modeleDao.findVyService(idservice);
	}

}
